@extends('Home/Layout/basecart')

@section('title', '确认订单')

@section('main')
    <!--头部-->

    <div class="cart-header wrapper">
        <div class="logo">
            <a href="index.html"><img src="{{asset('Home/img/logo.png')}}" alt="logo" /></a>
        </div>
        <div class="step-box">
            <div class="row">
                <div class="step first active col-3">
                    <span class="num">1</span><span class="line"></span><span class="label">我的购物车</span>
                </div>
                <div class="step active col-3">
                    <span class="num">2</span><span class="line"></span><span class="label">确认订单信息</span>
                </div>
                <div class="step col-3">
                    <span class="num">3</span><span class="line"></span><span class="label">选择支付方式</span>
                </div>
                <div class="step last col-3">
                    <span class="num">4</span><span class="line"></span><span class="label">完成付款</span>
                </div>
            </div>
        </div>
    </div>
    <!--头部-->
    <form action="{{url('/pay')}}" method="post" id="subform">
        {{csrf_field()}}
    <div class="wrapper confirm-wrap">
        <div class="confirm-tit">
            <span class="tit">选择收货地址 :</span>
        </div>
        <div class="confirm-address clearfix">
            @foreach($data['address'] as $val)
            <div class="col col-4">
                <div class="item {{$val->state == 1? 'active' : ''}}" {{$val->state == 1? 'id=address ' : ''}} aid="{{$val->id}}">
                    <div class="action">
                        <a class="edit" href="javascript:;">修改</a>
                    </div>
                    <div class="info">
                        <div class="ellipsis"><img src="{{asset('Home/img/ico/user.jpg')}}" alt="" />{{$val->link_man}} 收</div>
                        <div class="ellipsis"><img src="{{asset('Home/img/ico/dizhi.jpg')}}" alt="" />{{$val->address}}</div>
                        <div class="ellipsis"><img src="{{asset('Home/img/ico/tel.jpg')}}" alt="" />{{$val->phone}}</div>
                    </div>
                </div>
            </div>
            @endforeach

            <div class="col col-4">
                <a class="item va-m-box ta-c add">
                    <div class="add-new">
                        <span class="ico"><i class="iconfont icon-tianjia"></i></span>
                        <div class="label">添加收货地址</div>
                    </div>
                </a>
            </div>
        </div>
        <div class="confirm-address-bar"  style="display: none;">
            <a href="javascript:;" class="drop" data-action="drop">显示全部地址</a>
        </div>

        <div class="confirm-tit">
            <span class="tit">发票 :</span>
        </div>
        <div class="control-group">
            <div class="hd">
                发票抬头：
            </div>
            <div class="bd">
                <select class="ui-txtin" name="" id=""><option value="">个人</option></select>
                <input class="ui-txtin" style="width: 300px;"  type="text" name="" id="" value="本商城暂时不提供发票,敬请期待……" readonly/>
            </div>
        </div>
        <div class="confirm-tit">
            <span class="tit">确认商品信息:</span><div class="right"><a class="back" href="{{url('/cart')}}">返回购物车></a></div>
        </div>
        <div class="confirm-goods">
            <div class="confirm-goods-hd clearfix">
                <div class="col col1">商品信息:</div>
                <div class="col col2">单价（元）</div>
                <div class="col col3">数量</div>
                <div class="col col4">小计（元）</div>
            </div>
            @for ($i = 0; $i < count($data)-3; $i++)
                @foreach ($data[$i] as $item)
                    <div class="confirm-goods-bd">
                        <input type="hidden" name="pic[]" value="{{$item->pic}}">
                        <input type="hidden" name="color[]" value="{{$item->color}}">
                        <input type="hidden" name="size[]" value="{{$item->size}}">
                        <input type="hidden" name="gname[]" value="{{$item->gname}}">
                        <input type="hidden" name="price[]" value="{{$item->discount_price}}">
                        <input type="hidden" name="buynum[]" value="{{$item->buynum}}">
                        <input type="hidden" name="gid[]" value="{{$item->gid}}">
                        <input type="hidden" name="id[]" value="{{$item->id}}">
                        <div class="goods clearfix">
                            <div class="col col1">
                                <img src="{{asset($item->pic)}}" alt="">
                                <div class="info">
                                    <div class="name">{{$item->gname}}</div>
                                    <div class="meta"><span>{{$item->color}}</span><span>{{$item->size}}</span></div>
                                </div>
                            </div>
                            <div class="col col2">￥{{$item->discount_price}}</div>
                            <div class="col col3">{{$item->buynum}}</div>
                            <div class="col col4">￥{{$item->buynum*$item->discount_price}}</div>
                        </div>
                    </div>
                @endforeach
            @endfor

            <div class="confirm-goods-ft clearfix">
                <div class="fl"><span class="vm-ib">买家留言： </span><textarea class="ui-txtin" style="width: 410px;" name="message" placeholder="在此输入给商家的留言"></textarea></div>
                <div class="fr">
                    使用{{$data['sum']}}积分抵扣{{$data['sum']*0.01}}元:<input type="checkbox" name="userscore"  id="score" value="{{$data['sum']}}" style="width: 20px;height: 20px;margin-top: -40px;">
                    当前积分:<span id="sco" val="{{$data['score']}}">{{$data['score']}}</span>
                </div>
            </div>
        </div>

        <div class="confirm-total">
            <div class="box">
                <div class="item" id="ordersum">应付总额：<strong>¥<span id="osum">{{$data['sum']}}</span></strong></div>
                <?php $a = json_encode($data)  ?>
                <a class="ui-btn-theme go-charge" href="#"  id="gopay" >去支付</a>
            </div>
        </div>
    </div>
    </form>
    <!--脚部-->
    <div class="fatfooter">

    </div>
    <!--脚部-->
    <div id="addressform" style="display:none" class="layer-address">
            <div class="control-group">
                <div class="hd">
                    收货人姓名：
                </div>
                <div class="bd">
                    <input class="ui-txtin ui-txtin-thin" style="width: 200px;" type="text" name="link_man" id="addlinkman">
                </div>
            </div>
            <div class="control-group">
                <div class="hd">
                    联系电话：
                </div>
                <div class="bd">
                    <input class="ui-txtin ui-txtin-thin" style="width: 200px;" type="text" name="phone" id="addphone">
                </div>

            </div>
            <div class="control-group">
                <div class="hd vat">
                    所在地区：
                </div>
                <div class="bd">
                    <div class="mt10">
                        <input class="ui-txtin ui-txtin-thin" style="width: 560px;" type="text" name="" id="addaddr" placeholder="请填写具体地址">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <div class="hd vat">
                    邮政编码：
                </div>
                <div class="bd">
                    <input class="ui-txtin ui-txtin-thin" style="width: 200px;" type="text" name="code" id="addcode">
                </div>
            </div>

                <div class="bd">
                    设为默认地址： <input class="ui-txtin ui-txtin-thin" style="width: 50px;" type="checkbox" name="state" value="1" id="addstate">
                </div>

            <div class="control-bottom clearfix">
                <a href="javascript:void();" class="fl btn ui-btn-theme" id="saveaddress">保存</a><a href="" class="fr btn ui-btn cancle">取消</a>
            </div>
    </div>
@stop

@section('footer-js')
    <link rel="stylesheet" href="{{asset('Home/js/icheck/style.css')}}"/>
    <script src="{{asset('Home/js/icheck/icheck.min.js')}}"></script>
    <link rel="stylesheet" href="{{asset('Home/js/icheck/style.css')}}"/>
    <script src="{{asset('Home/js/icheck/icheck.min.js')}}"></script>
    <script src="{{asset('Home/js/layer/layer.js')}}"></script>
    <script src="{{asset('Home/js/global.js')}}"></script>
    <script>
        //这里不使用自带按钮，因为设计按钮较特殊，不准备作为通用样式
        $('.confirm-address .edit,.confirm-address .add').on('click',function () {
            layer.open({
                type: 1,
                skin: 'layui-layer-seaing',
                title: '标题',
                area: ['720px', 'auto'],
                content: $('#addressform')
                //btn: ['按钮一', '按钮二']
            });
        });
        $(document.body).on('click','.layer-address .cancle',function () {
            layer.closeAll();
            return false;
        })

        //
        function juggeAddressNum () {
            var col=$('.confirm-address .col'),
                cH=col.height();
            $('.confirm-address').height(cH)
            if (col.length>3) {
                $('.confirm-address-bar').show();
            }
            else {
                $('.confirm-address-bar').hide();
            }
        }
        juggeAddressNum();
        zAction.add({
            'drop':function () {
                $('.confirm-address').height('auto')
                var h=$('.confirm-address').height()
                juggeAddressNum();
                $('.confirm-address').animate({height: h}, 300);
                $(this).parent().remove();
            }
        });
    </script>
    <script>
       $('#score').on('click', function () {
           score = parseInt($('#score').val()) * 0.01
           osum = $('#osum').text()
           newsum = osum - osum*0.01
           if($("input[type='checkbox']").is(':checked')){
               $('#osum').text(newsum)
           }else{
               news = $('#score').val()
               $('#osum').text(news)
           }
       })
        $('#gopay').on('click',function () {

            id = $('#address').attr('aid')
            $('#address').append('<input type="hidden" name="aid" value="'+id+'">');
            document.getElementById('subform').submit();
        })
        
        $('.item').on('click',function () {
            $('.item').attr({class:"item"})
            $('.item').attr({id:""})
            $(this).attr({class:"item active"})
            $(this).attr({id:"address"})
        })
    </script>
{{--添加地址--}}
    <script>
        $('#addrform').on('click',function () {
           addlinkman = $('input[id=addlinkman]').val()
           addphone = $('input[id=addphone]').val()
           addcode = $('input[id=addcode]').val()
           addstate = $('input[id=addstate]').val()
           addaddr = $('input[id=addaddr]').val()
            $.ajax({
                type:'post',
                url:"{{url('/addr')}}",
                data:"link_man="+addlinkman+"&phone="+addphone+"&code="+addcode+"&state="+addstate+"&address="+addaddr,
                success: function (data) {
                },
                datatype:"json"
            })
        })

    </script>
@stop
